<!--  -->
<template>
  <div id="normal-preview-pdf">
    <!-- 新数据使用pdfjs展示 -->
    <base-modal-pdf
      :title="info.name || $t('common.base.previewPDF')"
      :info="info"
      :show.sync="visible"
      width="100%"
      class="batch-editing-customer-dialog"
    >
      <template slot="information">
        <div class="infor">{{ info.fileSize }}</div>
      </template>
      <div class="preview-pdf-box">
        <!--正式环境地址 `https://static.shb.ltd/pdfjs/web/viewer.html?file=${PDFUrl}&filename=${info.name}` -->
        <!--测试环境地址 `https://static-test.shb.ltd/pdfjs/web/viewer.html?file=${PDFUrl}&filename=${info.name}` -->
        <iframe
          style="width: 100%; height: 100vh; background: transparent"
          embedded="true"
          :src="`https://static.shb.ltd/pdfjs/web/viewer.html?file=${PDFUrl}&filename=${info.name}`"
        ></iframe>
      </div>
    </base-modal-pdf>
  </div>
</template>

<script>
export default {
  mounted() {},
  props: {
    url: {
      type: String,
    },
    info: {
      typeof: Object,
      default: () => {},
    },
  },
  data() {
    return {
      visible: false,
    };
  },
  computed:{
    PDFUrl(){
       if(/(http|https):\/\/([\w.]+\/?)\S*/ig.test(this.url)){
        // 绝对地址
        this.visible = true
        return encodeURIComponent(this.url)
       }else{
        // 相对地址,添加当前域名。用于匹配18年数据，给一个相对地址,部分数据302至https://file.shb.ltd下载文件，所有老数据不予展示直接下载
       let a = document.createElement('a');
        a.href = `/files/download?fileId=${this.info.id}`;
        a.download = this.info.fileName;
        a.click();
        window.URL.revokeObjectURL(a);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.preview-video-box {
  width: 100%;
  .preview-video {
    width: 100%;
    height: 100%;
    max-height: 80vh;
    background: #000000;
    object-fit: cover;
  }
}
.preview-pdf-box {
  width: 100%;
  height: 100vh;
  background: transparent;
  display: flex;
  justify-content: center;
  iframe {
    width: 100%;
    height: 100%;
  }
}
.infor {
  font-size: 14px;
  color: #8f8f8f;
  display: inline-flex;
  align-items: flex-end;
  padding-left: 15px;
}
.iframePDF{
  width: 100%; 
  height: 100vh; 
  background: transparent;
  position:fixed;
  z-index:1000;
  top:0;
  bottom:0;
}
</style>
